--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit c0e154c8862d2e0ae98fb3f7ff05cc0cc1a5fd28
Parents : 138b1be
Author : Sudo-Ivan <ivan@quad4.io>
Signature : Signature validation error
Date : 2026-03-05T16:00:13-06:00
Improve database health checks in IdentityContext: add checks for database integrity and health issues during setup and closure, updating app state accordingly.
Changes
1 files changed, 18 insertions(+), 1 deletions(-)
Diff
diff --git a/meshchatx/src/backend/identity_context.py b/meshchatx/src/backend/identity_context.py
index a00e6cf3..26e98fdc 100644
--- a/meshchatx/src/backend/identity_context.py
+++ b/meshchatx/src/backend/identity_context.py
@@ -96,8 +96,9 @@ class IdentityContext:
def setup(self):
print(f"Setting up Identity Context for {self.identity_hash}...")
- # 0. Clear any previous integrity issues on the app
+ # 0. Clear any previous integrity and database health issues on the app
self.app.integrity_issues = []
+ self.app.database_health_issues = []
# 1. Cleanup RNS state for this identity if any lingers
self.app.cleanup_rns_state_for_identity(self.identity.hash)
@@ -178,6 +179,14 @@ class IdentityContext:
self.database.provider.vacuum()
self.database.messages.mark_stuck_messages_as_failed()
+ if not getattr(self.app, "emergency", False):
+ db_issues = self.database.check_db_health_at_open(self.storage_path)
+ if db_issues:
+ self.app.database_health_issues = db_issues
+ print(
+ f"Database health check for {self.identity_hash}: {', '.join(db_issues)}",
+ )
+
# 4. Initialize LXMF Router
propagation_stamp_cost = self.config.lxmf_propagation_node_stamp_cost.get()
self.message_router = create_lxmf_router(
@@ -560,6 +569,14 @@ class IdentityContext:
if self.database:
try:
+ if not getattr(self.app, "emergency", False):
+ close_issues = self.database.check_db_health_at_close(
+ self.storage_path,
+ )
+ if close_issues:
+ print(
+ f"Database health at close for {self.identity_hash}: {', '.join(close_issues)}",
+ )
# 1. Checkpoint WAL and close database cleanly to ensure file is stable for hashing
self.database._checkpoint_and_close()
except Exception as e:
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────